package cn.bellychang.websocket;

import javax.websocket.ClientEndpoint;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import java.io.IOException;

/**
 * @author ChangLiang
 * @date 2020/3/5
 */
@ClientEndpoint
public class WebsocketClient {

    @OnOpen
    public void onOpen(Session session) {
        /// 模拟发送ping消息
        /*try {
            ByteBuffer applicationData = ByteBuffer.allocate(1);
            session.getBasicRemote().sendPing(applicationData);
        } catch (IOException e) {
            e.printStackTrace();
        }*/

        try {
            session.getBasicRemote().sendText("{'auth':'screen','module':'CRUCIAL','type':'FULL'}");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @OnMessage
    public void onMessage(String message) {
        System.out.println("java websocket client get message: " + message);
    }
}
